package com.his.back.service.serviceImpl;

import com.his.back.dao.drugMapper;
import com.his.back.dao.patient_drugMapper;
import com.his.back.pojo.drug;
import com.his.back.pojo.patient_drug;
import com.his.back.pojo.patient_drugKey;
import com.his.back.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class DrugServiceImpl implements DrugService {
    @Autowired
    drugMapper drugMapper;

    @Autowired
    patient_drugMapper patient_drugMapper;

    @Override
    public List<drug> search(String query) {
        return drugMapper.search(query);
    }

    @Override
    public int add(drug record) {
        return drugMapper.insertSelective(record);
    }

    @Override
    public int change(drug record) {
        return drugMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int delete(Integer record) {
        return drugMapper.deleteByPrimaryKey(record);
    }

    @Override
    public List<drug> patientOpen(String id, String date) throws ParseException {
        Date date1=null;
        DateFormat format= new SimpleDateFormat("yyyy-MM-dd");
        if(date!=null){
            date1=format.parse(date);
        }
        return drugMapper.patientOpen(id,date1);
    }

    @Override
    public List<drug> patientCancel(String id, String date) throws ParseException {
        Date date1=null;
        DateFormat format= new SimpleDateFormat("yyyy-MM-dd");
        if(date!=null){
            date1=format.parse(date);
        }
        return drugMapper.patientCancel(id,date1);
    }

    @Override
    public int update(patient_drug record) {
        return patient_drugMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public patient_drug find(patient_drugKey key) {
        return patient_drugMapper.selectByPrimaryKey(key);
    }
}
